//糊涂人寄信

//递归写法
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll f(ll n)
{
	if(n == 0)
		return 0;
	if(n == 1)
		return 0;
	if(n == 2)
		return 1;
	return (n-1)*(f(n-2)+f(n-1));
}

int main()
{
	ll n = 0;
	while(cin >> n)
	{
		ll ret = f(n);
		cout<<ret<<endl;
		
	}
	return 0;
}

//迭代写法
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
typedef long long ll;

int main()
{
	ll n = 0;
	while(cin >> n)
	{
		ll ret1 = 0;
		ll ret2 = 1;
		ll ret = 0;
		for(ll i = 3; i <= n; i++)
		{
			ret = (i-1)*(ret1 +ret2);
			ret1 = ret2;
			ret2 = ret;
		}
		if(n == 0 || n==1)
			cout<<0<<endl;
		else if(n == 2)
			cout<<1<<endl;
		else
			cout<<ret<<endl;
		
	}
	return 0;
}
